require('dotenv').config();

// 认证相关配置
const authConfig = {
  // JWT配置
  jwt: {
    secret: process.env.JWT_SECRET || 'default_jwt_secret_key',
    expiresIn: process.env.JWT_EXPIRES_IN || '24h',
    refreshExpiresIn: process.env.JWT_REFRESH_EXPIRES_IN || '7d',
    issuer: 'harmony-node-server',
    audience: 'harmony-app-users'
  },
  
  // 密码加密配置
  password: {
    saltRounds: 10,
    // 注意：根据数据库配置文档要求，需要支持md5加密
    useMd5: true
  },
  
  // 登录尝试限制
  loginAttempts: {
    maxAttempts: 5,
    lockoutDuration: 30 * 60 * 1000 // 30分钟
  },
  
  // 角色定义
  roles: {
    USER: 'user',
    ADMIN: 'admin'
  },
  
  // 权限定义
  permissions: {
    READ_USERS: 'read_users',
    WRITE_USERS: 'write_users',
    READ_CONTENTS: 'read_contents',
    WRITE_CONTENTS: 'write_contents'
  },
  
  // 角色权限映射
  rolePermissions: {
    user: ['read_contents'],
    admin: ['read_users', 'write_users', 'read_contents', 'write_contents']
  }
};

module.exports = authConfig;

// 导出常用的认证配置供其他模块使用
global.authConfig = authConfig;